package designpatterns.factory.abs.code;

import java.util.Objects;

/**
 * 工厂提供者
 */
public class FactoryProvider {
    public static PhoneAbstractFactory getFactory(String brand) throws RuntimeException {
        System.out.println("获取工厂:"+brand);
        PhoneAbstractFactory factory = null;
        switch (brand) {
            case "IPHONE":
                factory = new IPhoneFactory();
                break;
            case "MI":
                factory = new MiFactory();
                break;
        }
        if (Objects.isNull(factory)) {
            throw new RuntimeException("没有这样的工厂！");
        }
        return factory;
    }
}
